home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue37 / Clinic / CmdTest32U.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-05-30  |  1.7 KB  |  81 lines

  1. unit CmdTest32U;
  2.  
  3. {$ifdef Ver80} { Delphi 1.0x }
  4.   {$define DelphiLessThan3}
  5. {$endif}
  6. {$ifdef Ver90} { Delphi 2.0x }
  7.   {$define DelphiLessThan3}
  8.   {$define DelphiLessThan4}
  9.   {$define DelphiLessThan5}
  10. {$endif}
  11. {$ifdef Ver93} { C++ Builder 1.0x }
  12.   {$define DelphiLessThan3}
  13.   {$define DelphiLessThan4}
  14.   {$define DelphiLessThan5}
  15. {$endif}
  16. {$ifdef Ver100} { Delphi 3.0x }
  17.   {$define DelphiLessThan4}
  18.   {$define DelphiLessThan5}
  19. {$endif}
  20. {$ifdef Ver110} { C++ Builder 3.0x }
  21.   {$define DelphiLessThan4}
  22.   {$define DelphiLessThan5}
  23. {$endif}
  24. {$ifdef Ver120} { Delphi 4.0x }
  25.   {$define DelphiLessThan5}
  26. {$endif}
  27.  
  28. interface
  29.  
  30. uses
  31.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  32.   StdCtrls;
  33.  
  34. type
  35.   TForm1 = class(TForm)
  36.     Button1: TButton;
  37.     ListBox1: TListBox;
  38.     Edit1: TEdit;
  39.     procedure Button1Click(Sender: TObject);
  40.   private
  41.     { Private declarations }
  42.   public
  43.     { Public declarations }
  44.   end;
  45.  
  46. var
  47.   Form1: TForm1;
  48.  
  49. implementation
  50.  
  51. {$R *.DFM}
  52.  
  53. {$ifdef DelphiLessThan3}
  54. procedure Win32Check(RetVal: Bool);
  55. begin
  56.   if not RetVal then
  57.     raise Exception.Create(SysErrorMessage(GetLastError))
  58. end;
  59. {$endif}
  60.  
  61. procedure TForm1.Button1Click(Sender: TObject);
  62. var
  63.   SI: TStartupInfo;
  64.   PI: TProcessInformation;
  65.   ComSpec: array[0..MAX_PATH] of Char;
  66.   CmdLine: String;
  67. begin
  68.   GetEnvironmentVariable('COMSPEC', ComSpec, SizeOf(ComSpec));
  69.   CmdLine := String(ComSpec) + ' /C ' + Edit1.Text;
  70.   GetStartupInfo(SI);
  71.   Win32Check(
  72.     CreateProcess(
  73.       nil, PChar(CmdLine), nil, nil,
  74.       False, 0, nil, nil, SI, PI));
  75.   WaitForInputIdle(PI.hProcess, Infinite);
  76.   WaitForSingleObject(PI.hProcess, Infinite);
  77.   ListBox1.Items.LoadFromFile('C:\DirList.Txt')
  78. end;
  79.  
  80. end.
  81.